package com.keyinong.caizhengting.myfragement;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.keyinong.caizhengting.R;
import com.keyinong.caizhengting.tools.HttpTools;
import com.loopj.android.http.JsonHttpResponseHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

public class ServicecenterActivity extends Activity {

    HttpTools httpTools = null;
    String data;
    private ImageButton ib_fanhui;
    private TextView tv_tel;
    private String token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_servicecenter);
        getPhone();
        ib_fanhui = (ImageButton) findViewById(R.id.ib_fanhui10);
        ib_fanhui.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_tel = (TextView) findViewById(R.id.tv_tel);
        tv_tel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent in2 = new Intent();
                in2.setAction(Intent.ACTION_CALL);//指定意图动作
                in2.setData(Uri.parse("tel:" + data));//指定电话号码
                startActivity(in2);
            }
        });
    }

    private void getPhone() {

        SharedPreferences sp = getSharedPreferences("spReg", Context.MODE_PRIVATE);
        token = sp.getString("data", "");
        if (httpTools == null) {
            httpTools = new HttpTools(ServicecenterActivity.this);
        }
        httpTools.getPhone(token, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers,
                                  JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                try {
                    boolean code = response.getBoolean("code");
                    String msg = response.getString("msg");
                    Log.i("zq", "phone---" + response.toString());
                    if (code == true) {
                        data = response.getString("data");
//						Toast.makeText(BalancepayActivity.this, msg, Toast.LENGTH_SHORT).show();
                        //										view.setBackgroundResource(R.drawable.shouchang1);
                        tv_tel.setText(data);
                    } else {
                        Toast.makeText(ServicecenterActivity.this, msg, Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });

    }

}
